<?php
class MY_Controller extends CI_Controller
{
 function __construct()
 {
  parent::__construct();
  $this->load->library('template');
  //$this->layout->setLayout('layout_main');
  $this->load->helper('form');
  //$this->load->library('session');
  $this->load->helper('url');
  $this->load->library('SimpleLoginSecure');
  $this->load->helper('form');
  $this->load->library('session');
  $this->check_login();
  $this->compare_list();
  } 
  
  public function loadTemplate()
  {
      $this->template->write_view('header','main/header');
      $this->template->write_view('menu','main/menu');
      $this->template->write_view('slide','main/slide');
      $this->template->write_view('news','main/new');
      $this->template->write_view('searchzone','main/searchzone');
      $this->template->write_view('footer','main/footer');
  }
  
   public function check_login() {
    
		//$this->CI =& get_instance();
        //var_dump($this->session->userdata);
        if($this->session->userdata('logged_in')) 
        {
            $data['username']=$this->session->userdata('user_name');
            //var_dump($data);
            $this->template->write_view('loginform','user/logined',$data);
            $this->template->render('loginform');
        }
        else
        {
            $this->template->write_view('loginform','user/login_form');
            $this->template->render('loginform');
        }
    }
    
  public function compare_list()
  {
     $data['html']='';
     if(isset($this->session->userdata['items'])&&$this->session->userdata['items']!='')
     {
        $strproduct_id = $this->session->userdata['items'];
        if($strproduct_id!='')
        {
        $this->load->model('sanpham');
            $arrProducts= explode(',',$strproduct_id);
            foreach($arrProducts as $product){
                $product_db['id'] = $product;
                $product_db['name'] = $this->sanpham->get_product_name($product);
                $data['temp'][$product]=$product;
                $data['html'].='<li class="com'.$product_db['id'].'"><a href="javascript:void(0)" onclick="deleteCompare('.$product_db['id'].')">'.$product_db['name'].'</a></li>';
            }
        }
     }
     else{
        $data['html']='<li class="null_comp">Vui lòng chọn sản phẩm để so sánh</li>';
        }
        $this->template->write_view('compare','test/content',$data);
  }
}
?>